package com.stackexchange.webapis
{
	import com.stackexchange.webapis.client.StackExchangeService;
	import com.stackexchange.webapis.events.StackExchangeFaultEvent;
	import com.stackexchange.webapis.events.StackExchangeResultEvent;
	
	import org.flexunit.asserts.assertFalse;
	import org.flexunit.asserts.assertNotNull;
	import org.flexunit.asserts.assertTrue;
	import org.flexunit.async.Async;

	public class BadgesTest extends BaseTest
	{
		
		[Test(async)]
		public function badgesGetAll():void
		{
			function handleResult(event:StackExchangeResultEvent, passThroughData:Object):void
			{
				assertTrue(event.success);
				assertNotNull(event.data.badges);
			}
			
			var passThroughData:Object = new Object();
		    service.badges.addEventListener(StackExchangeResultEvent.BADGES_GET_ALL, 
		               						Async.asyncHandler(this, handleResult, TestConstants.timeout, passThroughData, handleTimeout), 
		               						false, 0, true);
		    service.badges.getAll();
		}
		
		[Test(async)]
		public function badgesGetUsersByExistingBadgeId():void
		{
			function handleResult(event:StackExchangeResultEvent, passThroughData:Object):void
			{
				assertTrue(event.success);
				assertNotNull(event.data.badges);
			}
			
			var passThroughData:Object = new Object();
			service.badges.addEventListener(StackExchangeResultEvent.BADGES_GET_BY_USER, 
				Async.asyncHandler(this, handleResult, TestConstants.timeout, passThroughData, handleTimeout), 
				false, 0, true);
			service.badges.getUsersByBadgeId([TestConstants.badgeId]);
		}
		
		[Test(async)]
		public function badgesGetUsersByWrongFormatedBadgeId():void
		{
			function handleResult(event:StackExchangeFaultEvent, passThroughData:Object):void
			{
				assertNotNull(event.data);
			}
			
			var passThroughData:Object = new Object();
			service.addEventListener(StackExchangeFaultEvent.FAULT, 
				Async.asyncHandler(this, handleResult, TestConstants.timeout, passThroughData, handleTimeout), 
				false, 0, true);
			service.badges.getUsersByBadgeId([TestConstants.wrongFormatedId]);
		}
		
		[Test(async)]
		public function badgesGetName():void
		{
			function handleResult(event:StackExchangeResultEvent, passThroughData:Object):void
			{
				assertTrue(event.success);
				assertNotNull(event.data.badges);
			}
			
			var passThroughData:Object = new Object();
			service.badges.addEventListener(StackExchangeResultEvent.BADGES_GET_ALL_NAME, 
				Async.asyncHandler(this, handleResult, TestConstants.timeout, passThroughData, handleTimeout), 
				false, 0, true);
			service.badges.getAllName();
		}
		
		[Test(async)]
		public function badgesGetAllTags():void
		{
			function handleResult(event:StackExchangeResultEvent, passThroughData:Object):void
			{
				assertTrue(event.success);
				assertNotNull(event.data.badges);
			}
			
			var passThroughData:Object = new Object();
			service.badges.addEventListener(StackExchangeResultEvent.BADGES_GET_All_TAGS, 
				Async.asyncHandler(this, handleResult, TestConstants.timeout, passThroughData, handleTimeout), 
				false, 0, true);
			service.badges.getAllTags();
		}
	}
}